package com.kgame5.xtank3d.app.gamecore.pane.readygo {
import kgame5.kutil.KEvent;
import kgame5.kutil.T;

import flash.display.MovieClip;
import flash.events.Event;
import flash.events.EventDispatcher;

/**
 * @author kk
 */
public class ReadyGoComp extends EventDispatcher{
	
	public static const EVENTTYPE_GO:String="EVENTTYPE_GO";
	
	private var mc:MovieClip;
	
	public function ReadyGoComp(mc:MovieClip){
		this.mc=mc;
		mc.visible=false;
	}
	
	public function start():void{
		//T.p(this,"------------start");
		mc.visible=true;
		mc.gotoAndPlay(1);
		mc.addEventListener(Event.ENTER_FRAME, onEnterFrame);
	}
	
	private function onEnterFrame(e:Event):void{
		//T.p(mc.currentFrame,mc.totalFrames);
		if(mc.currentFrame==mc.totalFrames){
			this.clear();
			this.dispatchEvent(new KEvent(EVENTTYPE_GO));
		}
	}
	
	public function clear():void{
		mc.visible=false;
		mc.gotoAndStop(1);//这个要是stop就会有问题
		mc.removeEventListener(Event.ENTER_FRAME, onEnterFrame);
	}
}//end of class
}
